package cn.bigcontainer.alt.sys.controller;

import cn.bigcontainer.alt.common.exception.BigResultCode;
import cn.bigcontainer.alt.sys.dto.SysDistrictDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.annotation.Resource;

import cn.bigcontainer.alt.sys.util.SysConstant;

import cn.bigcontainer.alt.sys.service.SysDistrictService;

import java.util.List;

/**
 * 行政区域的Controller类，用于处理用户请求.
 *
 * @author jiaod
 * @date 2021-06-15
 */
@Controller
@SessionAttributes(SysConstant.SESSION_USER)
@RequestMapping("/sys/district")
public class SysDistrictController {

	@Resource
	private SysDistrictService sysDistrictService;

	/**
	 * 获取省市行政区域数据
	 * @param province 省代码
	 * @param city 地市代码
	 * @return 返回所有省，以及province对应省的所有地市
	 */
	@RequestMapping
	@ResponseBody
	public BigResultCode getProvinceCityDistricts(String province, String city) {
		List<List<SysDistrictDto>> districts = sysDistrictService.getProvinceCityDistricts(province, city);
		return BigResultCode.getSuccessCode().setContent(districts);
	}

}
